package cn.edu.swufe.stu2025.myapplication;

import android.content.Intent;
import android.nfc.Tag;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class settingActivity extends AppCompatActivity {

    private static final String TAG="settingActivity";
    EditText inpDollar,inpEuro,inpWon;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_setting);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        //传入数据
        Intent intent = getIntent();
        float dollar = intent.getFloatExtra("key_dollar",0.1f);
        float euro =  intent.getFloatExtra("key_euro",0.1f);
        float won= intent.getFloatExtra("key_won",0.1f);

        inpDollar = findViewById(R.id.dollar_rate);
        inpEuro = findViewById(R.id.euro_rate);
        inpWon = findViewById(R.id.won_rate);

        //显示数据
        inpDollar.setText(String.valueOf(dollar));
        inpEuro.setText(String.valueOf(euro));
        inpWon.setText(String.valueOf(won));

    }
    //传入数据

    public void save(View btn){
        String dollarStr = inpDollar.getText().toString();
        String euroStr = inpEuro.getText().toString();
        String wonStr = inpWon.getText().toString();

        Log.i(TAG, "dollarStr="+dollarStr);
        Log.i(TAG, "euroStr="+euroStr);
        Log.i(TAG, "wonStr="+wonStr);

        //带回数据
        Intent retIntent = getIntent();
        Bundle bdl = new Bundle();
        bdl.putFloat("ret_dollar",Float.parseFloat(dollarStr));
        bdl.putFloat("ret_euro",Float.parseFloat(euroStr));
        bdl.putFloat("ret_won",Float.parseFloat(wonStr));
        retIntent.putExtras(bdl);
        setResult(3,retIntent);
        finish();
    }

}